<?php

namespace app\common\model;

use think\Model;

class Article extends Model
{
    public function cate()
    {
        return $this->belongsTo('Cate', 'cateid', 'id');
    }

    public function add($data)
    {
        $validate = new \app\common\validate\Article();
        if (!$validate->scene('add')->check($data)) {
            return $validate->getError();
        }
        $result = $this->save($data);
        if ($result) {
            return 1;
        }else {
            return '文章添加失败！';
        }
    }

    public function edit($data)
    {
        $validate = new \app\common\validate\Article();
        if (!$validate->scene('edit')->check($data)) {
            return $validate->getError();
        }
        $result = $this->isUpdate(true)->save($data);
        if ($result) {
            return 1;
        }else {
            return '文章修改失败！';
        }
    }
}
